package com.enlorenz.core.queue.proc;

import java.util.Collection;

import com.enlorenz.common.util.DataDetUtils;
import com.enlorenz.core.engine.AbstractBuzHandler;
import com.enlorenz.core.engine.imp.thread.ControlThread;
import com.enlorenz.core.queue.transfer.imp.WaitMessageQueue;

/**
 * 循环线程管理类
 * 获取IMessage对象列表
 * @author lcb
 */
public abstract class AbstractListCycleThread<T> extends ControlThread{
	private WaitMessageQueue<T> waitMessageQueue;
	{
		buzHandler=new AbstractBuzHandler() {
			
			@Override
			protected void onFinallyDo() {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			protected void onExceptionHappened(Exception e) {
				// TODO Auto-generated method stub
				
			}
			
			/**
			 * 线程开始必须做的
			 * @throws Exception
			 */
			protected void doWhenStart() throws Exception{
				
			}
			
			@Override
			protected void buzHandleImp() throws Exception {
				Collection<T> messageList = waitMessageQueue.getMsgColl();
				if (DataDetUtils.isCollectionEmpty(messageList)) {
					return;
				}
				//初始化时间
				initDate();
				process(messageList);
			}
		};
	}
	/**
	 * 处理接收到的结果数组
	 * @param messageList
	 */
	protected abstract void process(Collection<T> messageList);
	
	/**
	 * 设置等待队列对象
	 * @param waitMessageQueue 等待队列对象
	 */
	public void setWaitMessageQueue(WaitMessageQueue<T> waitMessageQueue) {
		this.waitMessageQueue = waitMessageQueue;
	}
}
